<template>
	<view>
		<cu-custom bgColor="bg-gradual-pink" :isBack="true"><block slot="backText">返回</block>
			<block slot="content">{{state==2?'待审核':''}}会员列表</block>
		</cu-custom>
		<view  class="userlist" >
			<view class="flex csuser-info"  v-for="(item,index) in newul">
				<view class="user-headimg"><image :src="item.headimg"></image></view>
				<view class="user-joinre">
					<view class="user-nickname">{{item.nickname}}</view>
					<view class="user-reason" v-if="state==2">申请理由:{{item.reason}}</view>
				</view>
				<view class="flex user-check" v-if="state==2">
					<button class="bg-blue" @tap="join_pass" :data-cuid="item.id">通过</button>
					<button class="bg-blue" @tap="join_reject" :data-cuid="item.id">拒绝</button>
				</view>
			</view>
			
		</view>
	</view>
</template>

<script>
	export default {
		onLoad(option){
			this.state=option.state;
			this.csid=option.csid;
			
		},
		onShow() {
			uni.request({
				url:"https://www.52tennis.cn/Club_Soci/GetUserList",
				data: {
					cid:this.csid,
					type:this.state,
					pagesize:10,
					currpage:1,
					nickname:''
				},
				success:(data)=> {
					console.log(data.data);
					if(data.data.result!=1){
						
					}else{
						this.userList=data.data.returnjson;
						this.newul=this.userList;
					}
				},
			});
			
		},
		data() {
			return {
				state:2,
				csid:0,
				userList:[],
				newul:[]
			}
		},
		methods: {
			join_pass(e){
				let cuid=e.currentTarget.dataset.cuid;
				console.log(cuid);
				uni.request({
					url:"https://www.52tennis.cn/Club_Soci/updateUserClubState",
					header:{
						'Content-Type': 'application/json;charset=UTF-8' //自定义请求头信息
					},
					method:'POST',
					data: {
						club_userid:cuid,
						state:1
					},
					success:(data)=> {
						console.log(data);
						if(data.data.result==1){
							
							let index = this.userList.findIndex(item=>{
								if(item.id==cuid){
									return true;
								}
							
							})
							this.userList.splice(index,1);
							this.newul=this.userList;
							uni.showToast({
								title: '审核通过',
								icon: 'success',
								mask: true,
								duration: 3000
							})
							
						}else{
							uni.showModal({
							    title: '提示',
							    content: data.data.msg,
							    success: function (res) {
							        if (res.confirm) {
							           uni.navigateBack({
							           	
							           })
							        } else if (res.cancel) {
							           
							        }
							    }
							});
						}
					},
				});
				
			},
			join_reject(e){
				let cuid=e.currentTarget.dataset.cuid;
				
				uni.request({
					url:"https://www.52tennis.cn/Club_Soci/updateUserClubState",
					header:{
						'Content-Type': 'application/json;charset=UTF-8' //自定义请求头信息
					},
					method:'POST',
					data: {
						club_userid:cuid,
						state:2
					},
					success:(data)=> {
						console.log(data);
						if(data.data.result==1){
							let index = this.userList.findIndex(item=>{
								if(item.id==cuid){
									return true;
								}
							
							})
							this.userList.splice(index,1);
							this.newul=this.userList;
							uni.showToast({
								title: '审核拒绝',
								icon: 'success',
								mask: true,
								duration: 3000
							})
						}else{
							uni.showModal({
							    title: '提示',
							    content: data.data.msg,
							    success: function (res) {
							        if (res.confirm) {
							           uni.navigateBack({
							           	
							           })
							        } else if (res.cancel) {
							           
							        }
							    }
							});
						}
					},
				});
			}
			
		}
	}
</script>

<style>
.userlist{
	padding: 30rpx;
}
.csuser-info{
	margin-bottom: 15rpx;
}
.user-headimg{
	width:15%;
}
.user-headimg image{
	border-radius: 50%;
	width:80rpx;
	height: 80rpx;
}
.user-joinre{
	width:50%;
}

.user-check{
	width:35%;
	align-items: center;
}
.user-check button{
	height: 50rpx;
	line-height: 50rpx;
	font-size: 24rpx;
}

.user-nickname{
	font-size: 32rpx;
	color: black;
}

.user-reason{
	font-size: 26rpx;
	overflow: hidden;
	height: 34rpx;
}

</style>
